package cn.strutsDemo.action;

import cn.strutsDemo.util.BaseAction;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class HelloAction extends ActionSupport implements Action {
    private String userName;
    private String msg;
    private String pwd;

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    @Override
    public String execute() throws Exception {
       if("admin".equals(this.getUserName())&&"admin".equals(this.getPwd())){
           BaseAction.getSession().put("userName",this.getUserName());
           return "success";
       }else{
           return "error";
       }
    }

    @Override
    public void validate() {
       if(this.getUserName().length()==0){
           addFieldError("userName","用户名不能为空");
       }
       if(this.getPwd().length()==0){
           addFieldError("pwd","密码不能为空");
       }
    }
}
